# 测试清空所有日志的修复
Write-Host "=== 测试清空所有日志修复 ===" -ForegroundColor Green

# 1. 检查当前日志状态
Write-Host "`n1. 检查当前日志状态..." -ForegroundColor Yellow
try {
    $logsResponse = Invoke-RestMethod -Uri "http://localhost:5252/api/log/list?pageSize=1" -Method GET
    Write-Host "✓ 当前总日志数: $($logsResponse.total)" -ForegroundColor Green
} catch {
    Write-Host "✗ 获取日志失败: $($_.Exception.Message)" -ForegroundColor Red
}

# 2. 使用当前时间清理所有日志
Write-Host "`n2. 使用当前时间清理所有日志..." -ForegroundColor Yellow
$currentDate = (Get-Date).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")
Write-Host "使用日期: $currentDate"

try {
    $cleanResponse = Invoke-RestMethod -Uri "http://localhost:5252/api/log/clean?beforeDate=$currentDate" -Method DELETE
    Write-Host "✓ 清理API调用成功" -ForegroundColor Green
    Write-Host "清理结果: $($cleanResponse | ConvertTo-Json)" -ForegroundColor Green
} catch {
    Write-Host "✗ 清理API调用失败: $($_.Exception.Message)" -ForegroundColor Red
}

# 3. 检查清理后的状态
Write-Host "`n3. 检查清理后的状态..." -ForegroundColor Yellow
try {
    $afterCleanResponse = Invoke-RestMethod -Uri "http://localhost:5252/api/log/list?pageSize=1" -Method GET
    Write-Host "✓ 清理后总日志数: $($afterCleanResponse.total)" -ForegroundColor Green
    
    if ($afterCleanResponse.total -eq 0) {
        Write-Host "✓ 所有日志已成功清理！" -ForegroundColor Green
    } else {
        Write-Host "⚠ 仍有 $($afterCleanResponse.total) 条日志未被清理" -ForegroundColor Yellow
    }
} catch {
    Write-Host "✗ 检查清理后状态失败: $($_.Exception.Message)" -ForegroundColor Red
}

Write-Host "`n=== 测试完成 ===" -ForegroundColor Green 